ConfigApi

object ConfigApi

API for management of config files. If writing in Java, consider using ConfigApiJava where possible.

Configs can de/serialized from File, string, or raw TomlElement. File read/write is performed with validation and correction.

The wiki has several articles related to using and designing configs

Author

fzzyhmstrs

Since

0.1.0

Functions

Link copied to clipboard

Returns a set of Action annotated onto the provided input

Link copied to clipboard
fun <T : Any> buildTranslations(kClass: KClass<T>, id: Identifier, lang: String, logWarnings: Boolean, builder: BiConsumer<String, String>)

Applies a set of translations for the provided class object to the provided builder. Uses Translatable.Name, Translatable.Desc, and Translatable.Prefix annotations to power the generation. TomlComment and Comment can be used to provide en_us description lang.

Link copied to clipboard
fun <T : Any> deserializeConfig(config: T, string: String, errorHeader: String = "", flags: Byte = 1): ValidationResult<T>
fun <T : Any> deserializeConfig(config: T, string: String, errorBuilder: MutableList<String>, flags: Byte = 1): ValidationResult<ConfigContext<T>>

Deserializes a config from a string.

Link copied to clipboard
fun <T : Any> deserializeFromToml(config: T, toml: TomlElement, errorHeader: String = "", flags: Byte = 1): ValidationResult<T>
fun <T : Any> deserializeFromToml(config: T, toml: TomlElement, errorBuilder: MutableList<String>, flags: Byte = 1): ValidationResult<ConfigContext<T>>
fun <T : Any> deserializeFromToml(config: T, toml: TomlElement, errorBuilder: ValidationResult.ErrorEntry.Mutable, flags: Byte = 1): ValidationResult<T>

Deserializes a config class from a TomlElement

Link copied to clipboard

Provides an instance of the EventApi for registering to config events

Link copied to clipboard

Whether a config corresponding to the provided scope is registered

Returns whether a config corresponding to the provided scope has been loaded or not, on the specified load side.

Link copied to clipboard

Determines if a Config GUI is open currently.

Link copied to clipboard
fun makeDir(folder: String, subfolder: String): Pair<File, Boolean>

Creates a config directory keyed off the standard Fabric Config Directory

Link copied to clipboard

Provides an instance of the NetworkApi for usage of the built-in cross-loader networking API

Link copied to clipboard
fun openScreen(scope: String)

Opens a config GUI. Does nothing on the server (But is not marked with @Environment, allowing for safe inclusion anywhere in code)

Link copied to clipboard
fun parseReader(reader: Reader): TomlElement

Parses a resource reader into a TomlElement for use in Codecs or other things.

Link copied to clipboard

Provides an instance of the PlatformApi for usage of the built-in cross-loader utilities

Link copied to clipboard
fun <T : Config> readOrCreateAndValidate(configClass: () -> T): T

overload of readOrCreateAndValidate that automatically applies the name, folder, and subfolder from the config itself. Automatically adds ".toml" to the name for reading and writing.

fun <T : Config> readOrCreateAndValidate(name: String, folder: String = "", subfolder: String = "", configClass: Supplier<T>): T
fun <T : Config> readOrCreateAndValidate(name: String, folder: String = "", subfolder: String = "", configClass: () -> T): T

Reads a config from File or Creates a new config class; writes out any corrections, updates, or new content to File. Automatically adds ".toml" to the name for reading and writing.

Link copied to clipboard
fun <T : Config> registerAndLoadConfig(configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T
fun <T : Config> registerAndLoadConfig(configClass: () -> T, registerType: RegisterType = RegisterType.BOTH): T

Creates and registers a Config. Use this over registerConfig and readOrCreateAndValidate if possible.

Link copied to clipboard
fun <T : Config> registerAndLoadNoGuiConfig(configClass: Supplier<T>, registerType: RegisterType = RegisterType.CLIENT): T

Creates and registers a Config. Use this over registerConfig and readOrCreateAndValidate if possible.

Link copied to clipboard
fun <T : Config> registerConfig(config: T, configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T
fun <T : Config> registerConfig(config: T, configClass: () -> T, registerType: RegisterType = RegisterType.BOTH): T

Registers a Config to registries. Does NOT load or validate it from file. Use this if you have custom initialization to perform, otherwise use registerAndLoadConfig for full initialization functionality.

Link copied to clipboard

Registers a ConfigScreenProvider to the client config registry. This provider will have priority over the default screen manager if it provides a non-null screen or successfully opens its own screen.

Link copied to clipboard

Provides an instance of the ResultApi for creation of ResultProvider to indirectly refer to configs via scope strings

Link copied to clipboard
fun <T : Config> save(configClass: T)

Overload of saveManual that automatically fills in name, folder, and subfolder from the config itself.

Link copied to clipboard
fun <T : Config> saveManual(name: String, folder: String = "", subfolder: String = "", configClass: T)

Saves a config to file without reading or updating.

Link copied to clipboard
fun <T : Any> serializeConfig(config: T, errorHeader: String = "", flags: Byte = 1): ValidationResult<String>
fun <T : Any> serializeConfig(config: T, errorBuilder: MutableList<String>, flags: Byte = 1): String

Serializes a config class to a string.

Link copied to clipboard
fun <T : Any> serializeToToml(config: T, errorHeader: String = "", flags: Byte = 1): ValidationResult<TomlElement>
fun <T : Any> serializeToToml(config: T, errorBuilder: MutableList<String>, flags: Byte = 1): TomlElement
fun <T : Any> serializeToToml(config: T, errorBuilder: ValidationResult.ErrorEntry.Mutable, flags: Byte = 1): ValidationResult<TomlElement>

Serialize a config class to a TomlElement